<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="店铺排队">
<div class="xm-offline">
    <div class="row">
        <div class="panel">
            <div class="form-horizontal">
                <div class="panel-header">
                    <a href="${basepath}/rest/manage/lineup/toList">返回上一级</a>
                </div>
                <div class="panel-body">
                    <form id="lineForm" class="form-panel">
                        <h3>排队操作台</h3>
                        <hr>
                        <div id="lineupGrid"></div>
                    </form>
                </div>
                <div class="panel-body">
                    <form id="searchForm" class="form-panel">
                        <ul class="panel-content">
                            <li>
                                <div class="control-group span5">
                                    <div class="search-controls  controls">
                                        <input type="text" name="userName" id="userName" value="" placeholder="搜索关键字">
                                    </div>
                                </div>
                                <button type="submit" class="button  button-primary" style="margin-left: 15px;">
                                    查询
                                </button>
                            </li>
                        </ul>
                    </form>
                    <hr>
                    <div id="grid"></div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var storeID = getQueryString('storeID');
    var createTime = getQueryString('createTime');


    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title: '序号', dataIndex: 'id', elCls: 'center', width: '10%'},
                {title: '预定时间', dataIndex: 'createTime', elCls: 'center', width: '15%'},
                {title: '排队用户', dataIndex: 'userName', elCls: 'center', width: '15%'},
                {title: '排队桌号', dataIndex: 'type', elCls: 'center', width: '15%',renderer:function(type){
                    return type=type=='small'?'小桌':type=='big'?'大桌':'中桌'
                    }},
                {title: '排队号数', dataIndex: 'number', elCls: 'center', width: '15%'},
                {
                    title: '操作', dataIndex: 'id', elCls: 'center', width: '15%', renderer: function (value) {
                        return '<a href="javascript:deleteOne(' + value + ')">删除</a>';
                    }
                }
            ];
    $.ajax({
        type:'GET',
        dataType:'json',
        url: '/rest/manage/store/selectDayLineUp',
        data:{createTime:createTime},
        success:function (res) {
            store.setResult(res.data);
        }
    });
    var store = new Store({
                pageSize: 10	// 配置分页数目
            });
            grid = new Grid.Grid({
                render: '#grid',
                columns: columns,
                width: '100%',
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
                // 底部工具栏
                bbar: {
                    pagingBar: true
                }
            });
    grid.render();

    /*--------------------------排队操作台  begin--------------------*/
    var lineupColumns = [
        {
            title: '餐桌类型', dataIndex: 'type', elCls: 'center', width: '20%', renderer: function (value) {
                switch (value) {
                    case 'big':
                        return '大桌';
                    case 'middle':
                        return '中桌';
                    case 'small':
                        return '小桌';
                }
            }
        },
        {
            title: '当前排队位数', dataIndex: 'type', elCls: 'center', width: '20%', renderer: function (value, data) {
                switch (value) {//当前排队位数的判断
                    case 'big':
                        return data.bigSeatAmount == '' || data.bigSeatAmount == null ? 0 : data.bigSeatAmount;
                    case 'middle':
                        return data.middleSeatAmount == '' || data.middleSeatAmount == null ? 0 : data.middleSeatAmount;
                    case 'small':
                        return data.smallSeatAmount == '' || data.smallSeatAmount == null ? 0 : data.smallSeatAmount;
                }
            }
        },
        {title: '当前号数', dataIndex: 'number', elCls: 'center', width: '20%'},
        {title: '对应用户', dataIndex: 'userName', elCls: 'center', width: '20%'},
        {
            title: '操作',
            dataIndex: 'id',
            elCls: 'center',
            width: '20%',
            renderer: function (value) {
                return '<a href="javascript:nextTable(' + value + ')">下一桌</a>';
            }
        }
    ];
    var lineupStore = new Store({
                url: '/rest/manage/store/selectDayLineUpBySeat',
                autoLoad: true, //自动加载数据
                params: { //配置初始请求的参数
                    length: '10',
                    storeID: storeID,
                    createTime: createTime
                },
                pageSize: 10,	// 配置分页数目
                root: 'data',
                totalProperty: 'total'
            }),
            lineupGrid = new Grid.Grid({
                render: '#lineupGrid',
                columns: lineupColumns,
                width: '100%',
                loadMask: true, //加载数据时显示屏蔽层
                store: lineupStore,
            });
    lineupGrid.render();
    /*--------------------------排队操作台  end--------------------*/

    var form = new BUI.Form.Form({
        srcNode: '#searchForm'
    }).render();
    form.on('beforesubmit', function (ev) {
        //序列化成对象
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });

    //删除单个用户
    function deleteOne(value) {
        BUI.Message.Confirm('确认要删除吗？', function () {
            $.ajax({
                type: 'POST',
                url: '${basepath}/rest/manage/lineup/deleteJson',
                dataType: 'json',
                data: {
                    id: value
                },
                success: function () {
                    var obj = form.serializeToObject();
                    obj.start = 0; //返回第一页
                    store.load(obj);
                }
            });
        }, 'question');
    }

    var lineForm = new BUI.Form.Form({
        srcNode: '#searchForm'
    }).render();
    lineForm.on('beforesubmit', function (ev) {
        if (!lineForm.isValid()) {
        }
    });

    //下一桌点击操作
    function nextTable(value) {
        BUI.Message.Confirm('是否确定进入下一位？', function () {
            $.ajax({
                type: 'POST',
                url: '${basepath}/rest/manage/store/updateLineup',
                dataType: 'json',
                data: {
                    id: value
                },
                success: function () {
                    var obj = lineForm.serializeToObject();
                    obj.start = 0; //返回第一页
                    lineupStore.load(obj);
                }
            });
        }, 'question');
    }
</script>
</@page.pageBase>
